<template>
  <div class="app-container home" @wheel.prevent="handleScrollWheel">
    <!-- 动态背景网格 -->
    <div class="bg-grid"></div>
    
    <!-- 浮动装饰元素 -->
    <div class="floating-elements">
      <div class="float-element" :style="{top: '15%', left: '10%', animationDelay: '0s'}"></div>
      <div class="float-element" :style="{top: '60%', right: '15%', animationDelay: '1.2s', size: '180px'}"></div>
      <div class="float-element" :style="{bottom: '10%', left: '20%', animationDelay: '2.4s', size: '120px'}"></div>
    </div>

    <!-- 主内容容器 -->
    <div class="content-container">
      <!-- ZCN简介 -->
      <el-row :gutter="24" class="intro-section">
        <el-col :span="24" class="text-center intro-content">     
          <div class="zcn-title" data-animate="fade-up">ZCN</div>
          <div class="zcn-fullname" data-animate="fade-up" data-delay="0.3s">Zone Create Novel</div>
          <div class="zcn-subtitle" data-animate="fade-up" data-delay="0.6s">创造新颖空间 · 创域家</div>
          <div class="zcn-tagline" data-animate="fade-up" data-delay="0.9s">精准聚焦 设计创新</div>     
          
          <!-- 优化后的日期显示 -->
          <div class="date-card" data-animate="fade-up" data-delay="1.2s">
            <div class="date-gregorian">
              <span class="date-day">{{ gregorianDay }}</span>
              <div class="date-month-year">
                <span class="date-month">{{ gregorianMonth }}</span>
                <span class="date-year">{{ gregorianYear }}</span>
              </div>
            </div>
            <div class="date-divider"></div>
            <div class="date-lunar">
              <div class="lunar-date">{{ lunarDate }}</div>
              <div class="lunar-weekday">{{ weekday }}</div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    
    <!-- 底部动态光效 -->
    <div class="bottom-glow"></div>
  </div>
</template>

<script>
import solarlunar from 'solarlunar';

export default {
  data() {
    return {
      nickName: (this.$store && this.$store.getters && this.$store.getters.nickName) || '用户',
      welcomeMessage: '',
      // 拆分日期数据
      gregorianYear: '',
      gregorianMonth: '',
      gregorianDay: '',
      weekday: '',
      lunarDate: ''
    }
  },
  mounted() {
    // 初始化时间
    this.updateTime();
    setInterval(() => this.updateTime(), 1000);
    
    // 设置欢迎信息
    this.setWelcomeMessage();
    
    // 初始化动画
    this.initAnimations();
    
    // 添加鼠标移动效果
    this.addMouseEffect();
  },
  beforeDestroy() {
    window.removeEventListener('mousemove', this.handleMouseMove);
    window.removeEventListener('scroll', this.handleScroll);
  },
  methods: {
    // 更新当前时间（优化版）
    updateTime() {
      const now = new Date();
      // 公历日期拆分
      this.gregorianYear = now.getFullYear();
      this.gregorianMonth = now.toLocaleString('zh-CN', { month: 'long' });
      this.gregorianDay = now.getDate();
      this.weekday = now.toLocaleString('zh-CN', { weekday: 'long' });

      // 农历日期
      const solarDate = solarlunar.solar2lunar(now.getFullYear(), now.getMonth() + 1, now.getDate());
      this.lunarDate = `农历${solarDate.lYear}年${solarDate.monthCn}${solarDate.dayCn}`;
    },
    
    // 设置欢迎信息
    setWelcomeMessage() {
      const hour = new Date().getHours();
      const messages = [
        { range: [0, 6], text: '夜深了，让灵感在静谧中沉淀' },
        { range: [6, 9], text: '晨光熹微，开启充满创意的一天' },
        { range: [9, 12], text: '专注当下，让每个设计都闪耀独特光芒' },
        { range: [12, 14], text: '午后小憩，为灵感充电续航' },
        { range: [14, 18], text: '灵感迸发，让创意化为现实' },
        { range: [18, 22], text: '华灯初上，梳理一天的设计成果' },
        { range: [22, 24], text: '夜色渐浓，让思绪在静谧中自由驰骋' }
      ];
      
      const message = messages.find(m => hour >= m.range[0] && hour < m.range[1]);
      this.welcomeMessage = message ? message.text : '欢迎回来，让我们继续创造';
    },
    
    // 初始化动画
    initAnimations() {
      // 初始检查动画元素
      this.checkAnimations();
      
      // 添加滚动监听
      window.addEventListener('scroll', this.handleScroll);
    },
    
    // 处理滚动事件
    handleScroll() {
      this.checkAnimations();
    },
    
    // 检查并触发动画
    checkAnimations() {
      const elements = document.querySelectorAll('[data-animate]');
      const windowHeight = window.innerHeight;
      
      elements.forEach(el => {
        const rect = el.getBoundingClientRect();
        const delay = el.getAttribute('data-delay') || '0s';
        
        if (rect.top < windowHeight * 0.85 && !el.classList.contains('animated')) {
          el.style.animationDelay = delay;
          el.classList.add('animated', el.getAttribute('data-animate'));
        }
      });
    },
    
    // 添加鼠标移动效果
    addMouseEffect() {
      window.addEventListener('mousemove', this.handleMouseMove);
    },
    
    // 处理鼠标移动
    handleMouseMove(e) {
      const x = e.clientX / window.innerWidth - 0.5;
      const y = e.clientY / window.innerHeight - 0.5;
      
      const floatElements = document.querySelectorAll('.float-element');
      floatElements.forEach((el, index) => {
        const factor = 0.03 * (index + 1);
        const size = el.style.size || '150px';
        el.style.transform = `translate(${x * factor * 100}px, ${y * factor * 100}px) scale(${1 + Math.sin(Date.now() * 0.001 + index) * 0.05})`;
      });
    }
  }
}
</script>

<style scoped>
/* 基础样式 */
.home {
  position: relative;
  height: calc(100vh - 83px); 
  color: #ffffff;
  overflow: hidden;
  background: #0f0b21; /* 深色主背景 */
  padding: 0;
}

.content-container {
  position: relative;
  z-index: 2;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 背景网格 */
.bg-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(rgba(100, 80, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 80, 255, 0.1) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: 1;
  animation: grid-move 80s linear infinite;
}

@keyframes grid-move {
  0% { background-position: 0 0; }
  100% { background-position: -800px -800px; }
}

/* 浮动装饰元素 */
.floating-elements {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.float-element {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(131, 56, 236, 0.3) 0%, rgba(58, 130, 246, 0) 70%);
  filter: blur(40px);
  transition: transform 0.5s ease-out;
  animation: pulse 8s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.4; }
}

/* 底部光效 */
.bottom-glow {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 300px;
  background: linear-gradient(180deg, rgba(131, 56, 236, 0) 0%, rgba(131, 56, 236, 0.2) 100%);
  z-index: 1;
  filter: blur(60px);
}

/* 简介区域 */
.intro-section {
  padding: 180px 0 80px;
}

.zcn-title {
  font-size: 12rem;
  font-weight: 900;
  margin: 0;
  background: linear-gradient(90deg, #6366f1, #ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
  opacity: 0;
  transform: translateY(30px);
  text-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.zcn-fullname {
  font-size: 1.8rem;
  color: #a5b4fc;
  margin: 20px 0 10px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  opacity: 0;
  transform: translateY(30px);
}

.zcn-subtitle {
  font-size: 2.2rem;
  color: #e0e7ff;
  margin: 15px 0;
  opacity: 0;
  transform: translateY(30px);
}

.zcn-tagline {
  font-size: 1.3rem;
  color: #93c5fd;
  font-weight: 300;
  letter-spacing: 0.2em;
  margin: 30px 0 0;
  opacity: 0;
  transform: translateY(30px);
}

/* 优化的日期卡片样式 */
.date-card {
  display: inline-flex;
  align-items: center;
  background: rgba(30, 25, 65, 0.7);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(100, 80, 255, 0.3);
  border-radius: 12px;
  padding: 15px 25px;
  margin-top: 50px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(30px);
  transition: all 0.5s ease;
}

.date-card:hover {
  box-shadow: 0 12px 40px rgba(99, 102, 241, 0.25);
  border-color: rgba(100, 80, 255, 0.4);
  transform: translateY(-3px);
}

/* 公历日期样式 */
.date-gregorian {
  display: flex;
  align-items: center;
  padding-right: 20px;
}

.date-day {
  font-size: 4rem;
  font-weight: 700;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
  margin-right: 15px;
  text-shadow: 0 2px 10px rgba(139, 92, 246, 0.3);
}

.date-month-year {
  text-align: left;
}

.date-month {
  display: block;
  font-size: 1.4rem;
  color: #e0e7ff;
  font-weight: 500;
}

.date-year {
  display: block;
  font-size: 1.2rem;
  color: #a5b4fc;
  margin-top: 5px;
}

/* 分隔线 */
.date-divider {
  width: 1px;
  height: 60px;
  background: linear-gradient(to bottom, transparent, rgba(100, 80, 255, 0.5), transparent);
  margin: 0 20px;
}

/* 农历日期样式 */
.date-lunar {
  padding-left: 20px;
  text-align: left;
}

.lunar-date {
  font-size: 1.2rem;
  color: #d1d5db;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.lunar-weekday {
  font-size: 1.1rem;
  color: #93c5fd;
  font-weight: 300;
}

/* 动画效果 */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

[data-animate].animated {
  animation-fill-mode: forwards;
  animation-duration: 0.8s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

.fade-up {
  animation-name: fade-up;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .zcn-title {
    font-size: 10rem;
  }
}

@media (max-width: 992px) {
  .zcn-title {
    font-size: 8rem;
  }
  
  .intro-section {
    padding: 150px 0 60px;
  }
}

@media (max-width: 768px) {
  .zcn-title {
    font-size: 6rem;
  }
  
  .zcn-fullname {
    font-size: 1.5rem;
    letter-spacing: 0.3em;
    text-indent: 0.3em;
  }
  
  .zcn-subtitle {
    font-size: 1.8rem;
  }
  
  /* 日期卡片响应式 */
  .date-card {
    flex-direction: column;
    padding: 20px;
    margin-top: 40px;
  }
  
  .date-gregorian {
    padding-right: 0;
    margin-bottom: 15px;
  }
  
  .date-divider {
    width: 60px;
    height: 1px;
    margin: 15px 0;
    background: linear-gradient(to right, transparent, rgba(100, 80, 255, 0.5), transparent);
  }
  
  .date-lunar {
    padding-left: 0;
    text-align: center;
  }
  
  .date-day {
    font-size: 3.5rem;
  }
}

@media (max-width: 576px) {
  .zcn-title {
    font-size: 4rem;
  }
  
  .zcn-fullname {
    font-size: 1.2rem;
    letter-spacing: 0.2em;
    text-indent: 0.2em;
  }
  
  .zcn-subtitle {
    font-size: 1.5rem;
  }
  
  .zcn-tagline {
    font-size: 1.1rem;
    letter-spacing: 0.1em;
  }
  
  /* 日期卡片小屏适配 */
  .date-day {
    font-size: 3rem;
  }
  
  .date-month {
    font-size: 1.2rem;
  }
  
  .date-year {
    font-size: 1rem;
  }
  
  .lunar-date, .lunar-weekday {
    font-size: 1rem;
  }
  
  .intro-section {
    padding: 120px 0 40px;
  }
}
</style>